package com.guigu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.guigu.mapper.PayMapper;
import com.guigu.pojo.Pay;
import com.guigu.pojo.Product;
import com.guigu.service.PayService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;

/**
 * <p>
 * 出库单表 服务实现类
 * </p>
 *
 * @author Mr.Zhang
 * @since 2025-03-12
 */
@Service
public class PayServiceImpl extends ServiceImpl<PayMapper, Pay> implements PayService {

    @Autowired
    private PayMapper payMapper;

    @Override
    public Page<Pay> payReview(HashMap<String, Object> map) {
        Integer currentPage = 1;
        Integer pageSize = 5;

        Object pageNumObj = map.get("currentPage");
        if (pageNumObj != null) {
            if (pageNumObj instanceof String && StringUtils.isNotBlank((String) pageNumObj)) {
                currentPage = Integer.parseInt((String) pageNumObj);
            } else if (pageNumObj instanceof Integer) {
                currentPage = (Integer) pageNumObj;
            }
        }
        Object pageSizeObj = map.get("pageSize");
        if (pageSizeObj != null) {
            if (pageSizeObj instanceof String && StringUtils.isNotBlank((String) pageSizeObj)) {
                pageSize = Integer.parseInt((String) pageSizeObj);
            } else if (pageSizeObj instanceof Integer) {
                pageSize = (Integer) pageSizeObj;
            }
        }

        Page<Pay> page = new Page<>(currentPage, pageSize);
        QueryWrapper<Pay> queryWrapper = new QueryWrapper<>();
        if (map.get("CheckTage") != null && StringUtils.isNotBlank((String) map.get("CheckTage"))) {
            queryWrapper.eq("check_tag", map.get("CheckTage"));
        }

        Page<Pay> payPage = payMapper.selectPage(page, queryWrapper);
        return payPage;
    }

    @Override
    public Page<Pay> payReview2(HashMap<String, Object> map) {
        Integer currentPage = 1;
        Integer pageSize = 5;

        Object pageNumObj = map.get("currentPage");
        if (pageNumObj != null) {
            if (pageNumObj instanceof String && StringUtils.isNotBlank((String) pageNumObj)) {
                currentPage = Integer.parseInt((String) pageNumObj);
            } else if (pageNumObj instanceof Integer) {
                currentPage = (Integer) pageNumObj;
            }
        }
        Object pageSizeObj = map.get("pageSize");
        if (pageSizeObj != null) {
            if (pageSizeObj instanceof String && StringUtils.isNotBlank((String) pageSizeObj)) {
                pageSize = Integer.parseInt((String) pageSizeObj);
            } else if (pageSizeObj instanceof Integer) {
                pageSize = (Integer) pageSizeObj;
            }
        }

        Page<Pay> page = new Page<>(currentPage, pageSize);
        QueryWrapper<Pay> queryWrapper = new QueryWrapper<>();
        if (map.get("outboundId") != null && StringUtils.isNotBlank((String) map.get("outboundId"))) {
            queryWrapper.like("pay_order_number", map.get("outboundId"));
        }
        if (map.get("status") != null && StringUtils.isNotBlank((String) map.get("status"))) {
            queryWrapper.like("check_tag", map.get("status"));
        }

        Page<Pay> payPage = payMapper.selectPage(page, queryWrapper);
        return payPage;
    }

    @Override
    public Pay getPayBypayOrderNumber(String payOrderNumber) {
        Pay pay = payMapper.selectOne(new QueryWrapper<Pay>().eq("pay_order_number", payOrderNumber));

        System.out.println(pay);

        return pay;
    }

    @Override
    public Pay getPayByOrderList(String OrderNumber) {
        Pay pay = payMapper.selectOne(new QueryWrapper<Pay>().eq("order_list", OrderNumber));
        return pay;
    }
}
